import service from './index'

/**
 * 创建订单
 * @param {Object} data - 订单数据
 * @param {Array} data.items - 订单项列表
 * @param {number} data.addressId - 收货地址ID
 * @param {string} data.paymentMethod - 支付方式
 * @returns {Promise}
 */
export const createOrder = (data) => {
  return service({
    url: '/orders',
    method: 'post',
    data
  })
}

/**
 * 获取订单列表
 * @param {Object} params - 查询参数
 * @param {number} params.page - 页码
 * @param {number} params.pageSize - 每页数量
 * @param {string} params.status - 订单状态
 * @returns {Promise}
 */
export const getOrderList = (params) => {
  return service({
    url: '/orders',
    method: 'get',
    params
  })
}

/**
 * 获取订单详情
 * @param {string} orderId - 订单ID
 * @returns {Promise}
 */
export const getOrderDetail = (orderId) => {
  return service({
    url: `/orders/${orderId}`,
    method: 'get'
  })
}

/**
 * 取消订单
 * @param {string} orderId - 订单ID
 * @returns {Promise}
 */
export const cancelOrder = (orderId) => {
  return service({
    url: `/orders/${orderId}/cancel`,
    method: 'put'
  })
}

/**
 * 确认收货
 * @param {string} orderId - 订单ID
 * @returns {Promise}
 */
export const confirmReceipt = (orderId) => {
  return service({
    url: `/orders/${orderId}/confirm`,
    method: 'put'
  })
}

/**
 * 删除订单
 * @param {string} orderId - 订单ID
 * @returns {Promise}
 */
export const deleteOrder = (orderId) => {
  return service({
    url: `/orders/${orderId}`,
    method: 'delete'
  })
}

/**
 * 获取订单统计信息
 * @returns {Promise}
 */
export const getOrderStats = () => {
  return service({
    url: '/orders/stats',
    method: 'get'
  })
}

/**
 * 获取销售订单列表（卖家查看）
 * @param {Object} params - 查询参数
 * @param {number} params.page - 页码
 * @param {number} params.pageSize - 每页数量
 * @param {string} params.status - 订单状态
 * @returns {Promise}
 */
export const getSellerOrders = (params) => {
  return service({
    url: '/orders/seller',
    method: 'get',
    params
  })
}

/**
 * 发货
 * @param {string} orderId - 订单ID
 * @param {Object} data - 物流信息
 * @param {string} data.logisticsCompany - 物流公司
 * @param {string} data.logisticsNumber - 物流单号
 * @returns {Promise}
 */
export const shipOrder = (orderId, data) => {
  return service({
    url: `/orders/${orderId}/ship`,
    method: 'put',
    data
  })
}

/**
 * 获取物流信息
 * @param {string} orderId - 订单ID
 * @returns {Promise}
 */
export const getLogisticsInfo = (orderId) => {
  return service({
    url: `/orders/${orderId}/logistics`,
    method: 'get'
  })
}

/**
 * 评价订单商品
 * @param {string} orderId - 订单ID
 * @param {Array} data - 评价数据
 * @returns {Promise}
 */
export const reviewOrder = (orderId, data) => {
  return service({
    url: `/orders/${orderId}/review`,
    method: 'post',
    data
  })
}

/**
 * 获取订单状态流转历史
 * @param {string} orderId - 订单ID
 * @returns {Promise}
 */
export const getOrderHistory = (orderId) => {
  return service({
    url: `/orders/${orderId}/history`,
    method: 'get'
  })
}
